#ifndef IP_H
#define IP_H

#include <QImage>
#include <opencv/cv.h>
#include <opencv/highgui.h>

struct RGB {
  unsigned char b, g, r;
  RGB(unsigned char r_, unsigned char g_, unsigned char b_)
    : b(b_), g(g_), r(r_) {}
  void set(const RGB& c)
  {
    *this = c;
  }
  void set(unsigned char r_, unsigned char g_, unsigned char b_)
  {
    r = r_;
    g = g_;
    b = b_;
  }
  bool operator == (const RGB& c) const
  {
    return b == c.b && g == c.g && r == c.r;
  }
  bool operator != (const RGB& c) const
  {
    return !(*this == c);
  }
  bool operator >= (const RGB& c) const
  {
    return b >= c.b && g >= c.g && r >= c.r;
  }
};

class IP
{
public:
  IP();

  static cv::Mat qimage2mat(const QImage& qimage);
  static QImage mat2qimage(const cv::Mat& mat);

  static RGB& getRGB(cv::Mat &mat, cv::Point p);
  static RGB& getRGB(cv::Mat &mat, int y, int x);
  static const RGB& getRGB(const cv::Mat &mat, int y, int x);

  static cv::Mat separateGround(cv::Mat& mat, RGB bg_color);
};

#endif // IP_H
